import JSEncrypt from 'jsencrypt';

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDaGaCnJU/Zq0/81RtdRTqxdlJOJVoqNikctT0bACiAimxrTxjCzE5vYsC/Azp0RopA4TfrdH7AL+09wDWY+ZzaqkVMjclctTPs/XBV8L92AKC1y8Ik+7znw3onyO74WA+3hjZ9TFVeQb76FSEAni1PdujKoNFaT8rYA0hc3yG3eQIDAQAB'

// 加密
export function encrypt(str: string): string {
    const encryptor = new JSEncrypt();
    encryptor.setPublicKey(publicKey);
    const result = encryptor.encrypt(str);
    if (typeof result === 'string') {
        return result;
    }
    return '';
}

// 解密
export function decrypt(str: string) {
    const encryptor = new JSEncrypt();
    encryptor.setPublicKey(publicKey);
    const result = encryptor.decrypt(str);
    if (typeof result === 'string') {
        return result;
    }
    return '';
}
